﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace FixtureManageSystem.Converters
{
    public class FullNameConverter : IMultiValueConverter
    {
         object IMultiValueConverter.Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            string PersonName = values[0] as string;
            string PersonNo = values[1] as string;
            if (string.IsNullOrEmpty(PersonNo) && string.IsNullOrEmpty(PersonName)){
                return "";
            }
            return $"{PersonName} - {PersonNo}";
        }

         object[] IMultiValueConverter.ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            string fullName = value as string;
            if (!string.IsNullOrEmpty(fullName))
            {
                string[] parts = fullName.Split(new char[] { ' ', '-' }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length == 2)
                {
                    return new object[] { parts[0], parts[1] };
                }
            }
            return null;
        }
    }
}
